package com.ddc.study.entity;

import java.util.Objects;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;

/**
 * Created on 2018/5/8.
 *
 * @author lshun
 * @version 1.0
 */
@Entity(tableName = "History")
public class History {
    @PrimaryKey(autoGenerate = true)
    @ColumnInfo(name = "dbId")
    public long dbId;

    @ColumnInfo(name = "searchWord")
    public String searchWord;

    @ColumnInfo(name = "searchTime")
    public long searchTime = System.currentTimeMillis();

    public void updateSearchTime() {
        searchTime = System.currentTimeMillis();
    }

    @NonNull
    @Override
    public String toString() {
        return "History{" +
                "dbId=" + dbId +
                ", searchWord='" + searchWord + '\'' +
                ", searchTime=" + searchTime +
                '}';
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        if (obj == this) return true;

        if (obj instanceof History) {
            History history = (History) obj;
            if (history.dbId != dbId) return false;
            if (history.searchTime != searchTime) return false;
            return Objects.equals(history.searchWord, searchWord);
        }
        return false;
    }
}
